1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.Application; 26 27 private import gio.ActionGroupIF; 28 private import gio.ActionGroupT; 29 private import gio.ActionMapIF; 30 private import gio.ActionMapT; 31 private import gio.ApplicationCommandLine; 32 private import gio.Cancellable; 33 private import gio.DBusConnection; 34 private import gio.FileIF; 35 private import gio.Notification; 36 private import gio.c.functions; 37 public import gio.c.types; 38 private import glib.ConstructionException; 39 private import glib.ErrorG; 40 private import glib.GException; 41 private import glib.OptionGroup; 42 private import glib.Str; 43 private import glib.VariantDict; 44 private import glib.c.functions; 45 private import gobject.ObjectG; 46 private import gobject.Signals; 47 private import std.algorithm; 48 49 50 /** 51 * A #GApplication is the foundation of an application. It wraps some 52 * low-level platform-specific services and is intended to act as the 53 * foundation for higher-level application classes such as 54 * #GtkApplication or #MxApplication. In general, you should not use 55 * this class outside of a higher level framework. 56 * 57 * GApplication provides convenient life cycle management by maintaining 58 * a "use count" for the primary application instance. The use count can 59 * be changed using g_application_hold() and g_application_release(). If 60 * it drops to zero, the application exits. Higher-level classes such as 61 * #GtkApplication employ the use count to ensure that the application 62 * stays alive as long as it has any opened windows. 63 * 64 * Another feature that GApplication (optionally) provides is process 65 * uniqueness. Applications can make use of this functionality by 66 * providing a unique application ID. If given, only one application 67 * with this ID can be running at a time per session. The session 68 * concept is platform-dependent, but corresponds roughly to a graphical 69 * desktop login. When your application is launched again, its 70 * arguments are passed through platform communication to the already 71 * running program. The already running instance of the program is 72 * called the "primary instance"; for non-unique applications this is 73 * always the current instance. On Linux, the D-Bus session bus 74 * is used for communication. 75 * 76 * The use of #GApplication differs from some other commonly-used 77 * uniqueness libraries (such as libunique) in important ways. The 78 * application is not expected to manually register itself and check 79 * if it is the primary instance. Instead, the main() function of a 80 * #GApplication should do very little more than instantiating the 81 * application instance, possibly connecting signal handlers, then 82 * calling g_application_run(). All checks for uniqueness are done 83 * internally. If the application is the primary instance then the 84 * startup signal is emitted and the mainloop runs. If the application 85 * is not the primary instance then a signal is sent to the primary 86 * instance and g_application_run() promptly returns. See the code 87 * examples below. 88 * 89 * If used, the expected form of an application identifier is the same as 90 * that of of a 91 * [D-Bus well-known bus name](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus). 92 * Examples include: `com.example.MyApp`, `org.example.internal_apps.Calculator`, 93 * `org._7_zip.Archiver`. 94 * For details on valid application identifiers, see g_application_id_is_valid(). 95 * 96 * On Linux, the application identifier is claimed as a well-known bus name 97 * on the user's session bus. This means that the uniqueness of your 98 * application is scoped to the current session. It also means that your 99 * application may provide additional services (through registration of other 100 * object paths) at that bus name. The registration of these object paths 101 * should be done with the shared GDBus session bus. Note that due to the 102 * internal architecture of GDBus, method calls can be dispatched at any time 103 * (even if a main loop is not running). For this reason, you must ensure that 104 * any object paths that you wish to register are registered before #GApplication 105 * attempts to acquire the bus name of your application (which happens in 106 * g_application_register()). Unfortunately, this means that you cannot use 107 * g_application_get_is_remote() to decide if you want to register object paths. 108 * 109 * GApplication also implements the #GActionGroup and #GActionMap 110 * interfaces and lets you easily export actions by adding them with 111 * g_action_map_add_action(). When invoking an action by calling 112 * g_action_group_activate_action() on the application, it is always 113 * invoked in the primary instance. The actions are also exported on 114 * the session bus, and GIO provides the #GDBusActionGroup wrapper to 115 * conveniently access them remotely. GIO provides a #GDBusMenuModel wrapper 116 * for remote access to exported #GMenuModels. 117 * 118 * There is a number of different entry points into a GApplication: 119 * 120 * - via 'Activate' (i.e. just starting the application) 121 * 122 * - via 'Open' (i.e. opening some files) 123 * 124 * - by handling a command-line 125 * 126 * - via activating an action 127 * 128 * The #GApplication::startup signal lets you handle the application 129 * initialization for all of these in a single place. 130 * 131 * Regardless of which of these entry points is used to start the 132 * application, GApplication passes some ‘platform data’ from the 133 * launching instance to the primary instance, in the form of a 134 * #GVariant dictionary mapping strings to variants. To use platform 135 * data, override the @before_emit or @after_emit virtual functions 136 * in your #GApplication subclass. When dealing with 137 * #GApplicationCommandLine objects, the platform data is 138 * directly available via g_application_command_line_get_cwd(), 139 * g_application_command_line_get_environ() and 140 * g_application_command_line_get_platform_data(). 141 * 142 * As the name indicates, the platform data may vary depending on the 143 * operating system, but it always includes the current directory (key 144 * "cwd"), and optionally the environment (ie the set of environment 145 * variables and their values) of the calling process (key "environ"). 146 * The environment is only added to the platform data if the 147 * %G_APPLICATION_SEND_ENVIRONMENT flag is set. #GApplication subclasses 148 * can add their own platform data by overriding the @add_platform_data 149 * virtual function. For instance, #GtkApplication adds startup notification 150 * data in this way. 151 * 152 * To parse commandline arguments you may handle the 153 * #GApplication::command-line signal or override the local_command_line() 154 * vfunc, to parse them in either the primary instance or the local instance, 155 * respectively. 156 * 157 * For an example of opening files with a GApplication, see 158 * [gapplication-example-open.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-open.c). 159 * 160 * For an example of using actions with GApplication, see 161 * [gapplication-example-actions.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-actions.c). 162 * 163 * For an example of using extra D-Bus hooks with GApplication, see 164 * [gapplication-example-dbushooks.c](https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-dbushooks.c). 165 * 166 * Since: 2.28 167 */ 168 public class Application : ObjectG, ActionGroupIF, ActionMapIF 169 { 170 /** the main Gtk struct */ 171 protected GApplication* gApplication; 172 173 /** Get the main Gtk struct */ 174 public GApplication* getApplicationStruct(bool transferOwnership = false) 175 { 176 if (transferOwnership) 177 ownedRef = false; 178 return gApplication; 179 } 180 181 /** the main Gtk struct as a void* */ 182 protected override void* getStruct() 183 { 184 return cast(void*)gApplication; 185 } 186 187 /** 188 * Sets our main struct and passes it to the parent class. 189 */ 190 public this (GApplication* gApplication, bool ownedRef = false) 191 { 192 this.gApplication = gApplication; 193 super(cast(GObject*)gApplication, ownedRef); 194 } 195 196 // add the ActionGroup capabilities 197 mixin ActionGroupT!(GApplication); 198 199 // add the ActionMap capabilities 200 mixin ActionMapT!(GApplication); 201 202 /** 203 * The ::command-line signal is emitted on the primary instance when 204 * a commandline is not handled locally. See g_application_run() and 205 * the #GApplicationCommandLine documentation for more information. 206 * 207 * Params: 208 * commandLine = a #GApplicationCommandLine representing the 209 * passed commandline 210 * 211 * Return: An integer that is set as the exit status for the calling 212 * process. See g_application_command_line_set_exit_status(). 213 */ 214 gulong addOnCommandLine(int delegate(Scoped!ApplicationCommandLine, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 215 { 216 return Signals.connect(this, "command-line", dlg, connectFlags ^ ConnectFlags.SWAPPED); 217 } 218 219 /** 220 * The ::open signal is emitted on the primary instance when there are 221 * files to open. See g_application_open() for more information. 222 * 223 * Params: 224 * files = an array of #GFiles 225 * nFiles = the length of @files 226 * hint = a hint provided by the calling instance 227 */ 228 gulong addOnOpen(void delegate(FileIF[], string, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 229 { 230 return Signals.connect(this, "open", delegate void (GFile* gfiles, int nFiles, string hint, Application app){ 231 FileIF[] files = new FileIF[nFiles]; 232 for(int i = 0; i < nFiles; i++) 233 { 234 files[i] = ObjectG.getDObject!FileIF((cast(GFile**)gfiles)[i]); 235 } 236 dlg(files, hint, app); 237 }, connectFlags ^ ConnectFlags.SWAPPED); 238 } 239 240 /** 241 */ 242 243 /** */ 244 public static GType getType() 245 { 246 return g_application_get_type(); 247 } 248 249 /** 250 * Creates a new #GApplication instance. 251 * 252 * If non-%NULL, the application id must be valid. See 253 * g_application_id_is_valid(). 254 * 255 * If no application ID is given then some features of #GApplication 256 * (most notably application uniqueness) will be disabled. 257 * 258 * Params: 259 * applicationId = the application id 260 * flags = the application flags 261 * 262 * Returns: a new #GApplication instance 263 * 264 * Throws: ConstructionException GTK+ fails to create the object. 265 */ 266 public this(string applicationId, GApplicationFlags flags) 267 { 268 auto __p = g_application_new(Str.toStringz(applicationId), flags); 269 270 if(__p is null) 271 { 272 throw new ConstructionException("null returned by new"); 273 } 274 275 this(cast(GApplication*) __p, true); 276 } 277 278 /** 279 * Returns the default #GApplication instance for this process. 280 * 281 * Normally there is only one #GApplication per process and it becomes 282 * the default when it is created. You can exercise more control over 283 * this by using g_application_set_default(). 284 * 285 * If there is no default application then %NULL is returned. 286 * 287 * Returns: the default application for this process, or %NULL 288 * 289 * Since: 2.32 290 */ 291 public static Application getDefault() 292 { 293 auto __p = g_application_get_default(); 294 295 if(__p is null) 296 { 297 return null; 298 } 299 300 return ObjectG.getDObject!(Application)(cast(GApplication*) __p); 301 } 302 303 /** 304 * Checks if @application_id is a valid application identifier. 305 * 306 * A valid ID is required for calls to g_application_new() and 307 * g_application_set_application_id(). 308 * 309 * Application identifiers follow the same format as 310 * [D-Bus well-known bus names](https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-bus). 311 * For convenience, the restrictions on application identifiers are 312 * reproduced here: 313 * 314 * - Application identifiers are composed of 1 or more elements separated by a 315 * period (`.`) character. All elements must contain at least one character. 316 * 317 * - Each element must only contain the ASCII characters `[A-Z][a-z][0-9]_-`, 318 * with `-` discouraged in new application identifiers. Each element must not 319 * begin with a digit. 320 * 321 * - Application identifiers must contain at least one `.` (period) character 322 * (and thus at least two elements). 323 * 324 * - Application identifiers must not begin with a `.` (period) character. 325 * 326 * - Application identifiers must not exceed 255 characters. 327 * 328 * Note that the hyphen (`-`) character is allowed in application identifiers, 329 * but is problematic or not allowed in various specifications and APIs that 330 * refer to D-Bus, such as 331 * [Flatpak application IDs](http://docs.flatpak.org/en/latest/introduction.html#identifiers), 332 * the 333 * [`DBusActivatable` interface in the Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus), 334 * and the convention that an application's "main" interface and object path 335 * resemble its application identifier and bus name. To avoid situations that 336 * require special-case handling, it is recommended that new application 337 * identifiers consistently replace hyphens with underscores. 338 * 339 * Like D-Bus interface names, application identifiers should start with the 340 * reversed DNS domain name of the author of the interface (in lower-case), and 341 * it is conventional for the rest of the application identifier to consist of 342 * words run together, with initial capital letters. 343 * 344 * As with D-Bus interface names, if the author's DNS domain name contains 345 * hyphen/minus characters they should be replaced by underscores, and if it 346 * contains leading digits they should be escaped by prepending an underscore. 347 * For example, if the owner of 7-zip.org used an application identifier for an 348 * archiving application, it might be named `org._7_zip.Archiver`. 349 * 350 * Params: 351 * applicationId = a potential application identifier 352 * 353 * Returns: %TRUE if @application_id is valid 354 */ 355 public static bool idIsValid(string applicationId) 356 { 357 return g_application_id_is_valid(Str.toStringz(applicationId)) != 0; 358 } 359 360 /** 361 * Activates the application. 362 * 363 * In essence, this results in the #GApplication::activate signal being 364 * emitted in the primary instance. 365 * 366 * The application must be registered before calling this function. 367 * 368 * Since: 2.28 369 */ 370 public void activate() 371 { 372 g_application_activate(gApplication); 373 } 374 375 /** 376 * Add an option to be handled by @application. 377 * 378 * Calling this function is the equivalent of calling 379 * g_application_add_main_option_entries() with a single #GOptionEntry 380 * that has its arg_data member set to %NULL. 381 * 382 * The parsed arguments will be packed into a #GVariantDict which 383 * is passed to #GApplication::handle-local-options. If 384 * %G_APPLICATION_HANDLES_COMMAND_LINE is set, then it will also 385 * be sent to the primary instance. See 386 * g_application_add_main_option_entries() for more details. 387 * 388 * See #GOptionEntry for more documentation of the arguments. 389 * 390 * Params: 391 * longName = the long name of an option used to specify it in a commandline 392 * shortName = the short name of an option 393 * flags = flags from #GOptionFlags 394 * arg = the type of the option, as a #GOptionArg 395 * description = the description for the option in `--help` output 396 * argDescription = the placeholder to use for the extra argument 397 * parsed by the option in `--help` output 398 * 399 * Since: 2.42 400 */ 401 public void addMainOption(string longName, char shortName, GOptionFlags flags, GOptionArg arg, string description, string argDescription) 402 { 403 g_application_add_main_option(gApplication, Str.toStringz(longName), shortName, flags, arg, Str.toStringz(description), Str.toStringz(argDescription)); 404 } 405 406 /** 407 * Adds main option entries to be handled by @application. 408 * 409 * This function is comparable to g_option_context_add_main_entries(). 410 * 411 * After the commandline arguments are parsed, the 412 * #GApplication::handle-local-options signal will be emitted. At this 413 * point, the application can inspect the values pointed to by @arg_data 414 * in the given #GOptionEntrys. 415 * 416 * Unlike #GOptionContext, #GApplication supports giving a %NULL 417 * @arg_data for a non-callback #GOptionEntry. This results in the 418 * argument in question being packed into a #GVariantDict which is also 419 * passed to #GApplication::handle-local-options, where it can be 420 * inspected and modified. If %G_APPLICATION_HANDLES_COMMAND_LINE is 421 * set, then the resulting dictionary is sent to the primary instance, 422 * where g_application_command_line_get_options_dict() will return it. 423 * This "packing" is done according to the type of the argument -- 424 * booleans for normal flags, strings for strings, bytestrings for 425 * filenames, etc. The packing only occurs if the flag is given (ie: we 426 * do not pack a "false" #GVariant in the case that a flag is missing). 427 * 428 * In general, it is recommended that all commandline arguments are 429 * parsed locally. The options dictionary should then be used to 430 * transmit the result of the parsing to the primary instance, where 431 * g_variant_dict_lookup() can be used. For local options, it is 432 * possible to either use @arg_data in the usual way, or to consult (and 433 * potentially remove) the option from the options dictionary. 434 * 435 * This function is new in GLib 2.40. Before then, the only real choice 436 * was to send all of the commandline arguments (options and all) to the 437 * primary instance for handling. #GApplication ignored them completely 438 * on the local side. Calling this function "opts in" to the new 439 * behaviour, and in particular, means that unrecognised options will be 440 * treated as errors. Unrecognised options have never been ignored when 441 * %G_APPLICATION_HANDLES_COMMAND_LINE is unset. 442 * 443 * If #GApplication::handle-local-options needs to see the list of 444 * filenames, then the use of %G_OPTION_REMAINING is recommended. If 445 * @arg_data is %NULL then %G_OPTION_REMAINING can be used as a key into 446 * the options dictionary. If you do use %G_OPTION_REMAINING then you 447 * need to handle these arguments for yourself because once they are 448 * consumed, they will no longer be visible to the default handling 449 * (which treats them as filenames to be opened). 450 * 451 * It is important to use the proper GVariant format when retrieving 452 * the options with g_variant_dict_lookup(): 453 * - for %G_OPTION_ARG_NONE, use `b` 454 * - for %G_OPTION_ARG_STRING, use `&s` 455 * - for %G_OPTION_ARG_INT, use `i` 456 * - for %G_OPTION_ARG_INT64, use `x` 457 * - for %G_OPTION_ARG_DOUBLE, use `d` 458 * - for %G_OPTION_ARG_FILENAME, use `^&ay` 459 * - for %G_OPTION_ARG_STRING_ARRAY, use `^a&s` 460 * - for %G_OPTION_ARG_FILENAME_ARRAY, use `^a&ay` 461 * 462 * Params: 463 * entries = a 464 * %NULL-terminated list of #GOptionEntrys 465 * 466 * Since: 2.40 467 */ 468 public void addMainOptionEntries(GOptionEntry[] entries) 469 { 470 g_application_add_main_option_entries(gApplication, entries.ptr); 471 } 472 473 /** 474 * Adds a #GOptionGroup to the commandline handling of @application. 475 * 476 * This function is comparable to g_option_context_add_group(). 477 * 478 * Unlike g_application_add_main_option_entries(), this function does 479 * not deal with %NULL @arg_data and never transmits options to the 480 * primary instance. 481 * 482 * The reason for that is because, by the time the options arrive at the 483 * primary instance, it is typically too late to do anything with them. 484 * Taking the GTK option group as an example: GTK will already have been 485 * initialised by the time the #GApplication::command-line handler runs. 486 * In the case that this is not the first-running instance of the 487 * application, the existing instance may already have been running for 488 * a very long time. 489 * 490 * This means that the options from #GOptionGroup are only really usable 491 * in the case that the instance of the application being run is the 492 * first instance. Passing options like `--display=` or `--gdk-debug=` 493 * on future runs will have no effect on the existing primary instance. 494 * 495 * Calling this function will cause the options in the supplied option 496 * group to be parsed, but it does not cause you to be "opted in" to the 497 * new functionality whereby unrecognised options are rejected even if 498 * %G_APPLICATION_HANDLES_COMMAND_LINE was given. 499 * 500 * Params: 501 * group = a #GOptionGroup 502 * 503 * Since: 2.40 504 */ 505 public void addOptionGroup(OptionGroup group) 506 { 507 g_application_add_option_group(gApplication, (group is null) ? null : group.getOptionGroupStruct(true)); 508 } 509 510 /** 511 * Marks @application as busy (see g_application_mark_busy()) while 512 * @property on @object is %TRUE. 513 * 514 * The binding holds a reference to @application while it is active, but 515 * not to @object. Instead, the binding is destroyed when @object is 516 * finalized. 517 * 518 * Params: 519 * object = a #GObject 520 * property = the name of a boolean property of @object 521 * 522 * Since: 2.44 523 */ 524 public void bindBusyProperty(ObjectG object, string property) 525 { 526 g_application_bind_busy_property(gApplication, (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property)); 527 } 528 529 /** 530 * Gets the unique identifier for @application. 531 * 532 * Returns: the identifier for @application, owned by @application 533 * 534 * Since: 2.28 535 */ 536 public string getApplicationId() 537 { 538 return Str.toString(g_application_get_application_id(gApplication)); 539 } 540 541 /** 542 * Gets the #GDBusConnection being used by the application, or %NULL. 543 * 544 * If #GApplication is using its D-Bus backend then this function will 545 * return the #GDBusConnection being used for uniqueness and 546 * communication with the desktop environment and other instances of the 547 * application. 548 * 549 * If #GApplication is not using D-Bus then this function will return 550 * %NULL. This includes the situation where the D-Bus backend would 551 * normally be in use but we were unable to connect to the bus. 552 * 553 * This function must not be called before the application has been 554 * registered. See g_application_get_is_registered(). 555 * 556 * Returns: a #GDBusConnection, or %NULL 557 * 558 * Since: 2.34 559 */ 560 public DBusConnection getDbusConnection() 561 { 562 auto __p = g_application_get_dbus_connection(gApplication); 563 564 if(__p is null) 565 { 566 return null; 567 } 568 569 return ObjectG.getDObject!(DBusConnection)(cast(GDBusConnection*) __p); 570 } 571 572 /** 573 * Gets the D-Bus object path being used by the application, or %NULL. 574 * 575 * If #GApplication is using its D-Bus backend then this function will 576 * return the D-Bus object path that #GApplication is using. If the 577 * application is the primary instance then there is an object published 578 * at this path. If the application is not the primary instance then 579 * the result of this function is undefined. 580 * 581 * If #GApplication is not using D-Bus then this function will return 582 * %NULL. This includes the situation where the D-Bus backend would 583 * normally be in use but we were unable to connect to the bus. 584 * 585 * This function must not be called before the application has been 586 * registered. See g_application_get_is_registered(). 587 * 588 * Returns: the object path, or %NULL 589 * 590 * Since: 2.34 591 */ 592 public string getDbusObjectPath() 593 { 594 return Str.toString(g_application_get_dbus_object_path(gApplication)); 595 } 596 597 /** 598 * Gets the flags for @application. 599 * 600 * See #GApplicationFlags. 601 * 602 * Returns: the flags for @application 603 * 604 * Since: 2.28 605 */ 606 public GApplicationFlags getFlags() 607 { 608 return g_application_get_flags(gApplication); 609 } 610 611 /** 612 * Gets the current inactivity timeout for the application. 613 * 614 * This is the amount of time (in milliseconds) after the last call to 615 * g_application_release() before the application stops running. 616 * 617 * Returns: the timeout, in milliseconds 618 * 619 * Since: 2.28 620 */ 621 public uint getInactivityTimeout() 622 { 623 return g_application_get_inactivity_timeout(gApplication); 624 } 625 626 /** 627 * Gets the application's current busy state, as set through 628 * g_application_mark_busy() or g_application_bind_busy_property(). 629 * 630 * Returns: %TRUE if @application is currently marked as busy 631 * 632 * Since: 2.44 633 */ 634 public bool getIsBusy() 635 { 636 return g_application_get_is_busy(gApplication) != 0; 637 } 638 639 /** 640 * Checks if @application is registered. 641 * 642 * An application is registered if g_application_register() has been 643 * successfully called. 644 * 645 * Returns: %TRUE if @application is registered 646 * 647 * Since: 2.28 648 */ 649 public bool getIsRegistered() 650 { 651 return g_application_get_is_registered(gApplication) != 0; 652 } 653 654 /** 655 * Checks if @application is remote. 656 * 657 * If @application is remote then it means that another instance of 658 * application already exists (the 'primary' instance). Calls to 659 * perform actions on @application will result in the actions being 660 * performed by the primary instance. 661 * 662 * The value of this property cannot be accessed before 663 * g_application_register() has been called. See 664 * g_application_get_is_registered(). 665 * 666 * Returns: %TRUE if @application is remote 667 * 668 * Since: 2.28 669 */ 670 public bool getIsRemote() 671 { 672 return g_application_get_is_remote(gApplication) != 0; 673 } 674 675 /** 676 * Gets the resource base path of @application. 677 * 678 * See g_application_set_resource_base_path() for more information. 679 * 680 * Returns: the base resource path, if one is set 681 * 682 * Since: 2.42 683 */ 684 public string getResourceBasePath() 685 { 686 return Str.toString(g_application_get_resource_base_path(gApplication)); 687 } 688 689 /** 690 * Increases the use count of @application. 691 * 692 * Use this function to indicate that the application has a reason to 693 * continue to run. For example, g_application_hold() is called by GTK+ 694 * when a toplevel window is on the screen. 695 * 696 * To cancel the hold, call g_application_release(). 697 */ 698 public void hold() 699 { 700 g_application_hold(gApplication); 701 } 702 703 /** 704 * Increases the busy count of @application. 705 * 706 * Use this function to indicate that the application is busy, for instance 707 * while a long running operation is pending. 708 * 709 * The busy state will be exposed to other processes, so a session shell will 710 * use that information to indicate the state to the user (e.g. with a 711 * spinner). 712 * 713 * To cancel the busy indication, use g_application_unmark_busy(). 714 * 715 * The application must be registered before calling this function. 716 * 717 * Since: 2.38 718 */ 719 public void markBusy() 720 { 721 g_application_mark_busy(gApplication); 722 } 723 724 /** 725 * Opens the given files. 726 * 727 * In essence, this results in the #GApplication::open signal being emitted 728 * in the primary instance. 729 * 730 * @n_files must be greater than zero. 731 * 732 * @hint is simply passed through to the ::open signal. It is 733 * intended to be used by applications that have multiple modes for 734 * opening files (eg: "view" vs "edit", etc). Unless you have a need 735 * for this functionality, you should use "". 736 * 737 * The application must be registered before calling this function 738 * and it must have the %G_APPLICATION_HANDLES_OPEN flag set. 739 * 740 * Params: 741 * files = an array of #GFiles to open 742 * hint = a hint (or ""), but never %NULL 743 * 744 * Since: 2.28 745 */ 746 public void open(FileIF[] files, string hint) 747 { 748 GFile*[] filesArray = new GFile*[files.length]; 749 for ( int i = 0; i < files.length; i++ ) 750 { 751 filesArray[i] = files[i].getFileStruct(); 752 } 753 754 g_application_open(gApplication, filesArray.ptr, cast(int)files.length, Str.toStringz(hint)); 755 } 756 757 /** 758 * Immediately quits the application. 759 * 760 * Upon return to the mainloop, g_application_run() will return, 761 * calling only the 'shutdown' function before doing so. 762 * 763 * The hold count is ignored. 764 * Take care if your code has called g_application_hold() on the application and 765 * is therefore still expecting it to exist. 766 * (Note that you may have called g_application_hold() indirectly, for example 767 * through gtk_application_add_window().) 768 * 769 * The result of calling g_application_run() again after it returns is 770 * unspecified. 771 * 772 * Since: 2.32 773 */ 774 public void quit() 775 { 776 g_application_quit(gApplication); 777 } 778 779 /** 780 * Attempts registration of the application. 781 * 782 * This is the point at which the application discovers if it is the 783 * primary instance or merely acting as a remote for an already-existing 784 * primary instance. This is implemented by attempting to acquire the 785 * application identifier as a unique bus name on the session bus using 786 * GDBus. 787 * 788 * If there is no application ID or if %G_APPLICATION_NON_UNIQUE was 789 * given, then this process will always become the primary instance. 790 * 791 * Due to the internal architecture of GDBus, method calls can be 792 * dispatched at any time (even if a main loop is not running). For 793 * this reason, you must ensure that any object paths that you wish to 794 * register are registered before calling this function. 795 * 796 * If the application has already been registered then %TRUE is 797 * returned with no work performed. 798 * 799 * The #GApplication::startup signal is emitted if registration succeeds 800 * and @application is the primary instance (including the non-unique 801 * case). 802 * 803 * In the event of an error (such as @cancellable being cancelled, or a 804 * failure to connect to the session bus), %FALSE is returned and @error 805 * is set appropriately. 806 * 807 * Note: the return value of this function is not an indicator that this 808 * instance is or is not the primary instance of the application. See 809 * g_application_get_is_remote() for that. 810 * 811 * Params: 812 * cancellable = a #GCancellable, or %NULL 813 * 814 * Returns: %TRUE if registration succeeded 815 * 816 * Since: 2.28 817 * 818 * Throws: GException on failure. 819 */ 820 public bool register(Cancellable cancellable) 821 { 822 GError* err = null; 823 824 auto __p = g_application_register(gApplication, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 825 826 if (err !is null) 827 { 828 throw new GException( new ErrorG(err) ); 829 } 830 831 return __p; 832 } 833 834 /** 835 * Decrease the use count of @application. 836 * 837 * When the use count reaches zero, the application will stop running. 838 * 839 * Never call this function except to cancel the effect of a previous 840 * call to g_application_hold(). 841 */ 842 public void release() 843 { 844 g_application_release(gApplication); 845 } 846 847 /** 848 * Runs the application. 849 * 850 * This function is intended to be run from main() and its return value 851 * is intended to be returned by main(). Although you are expected to pass 852 * the @argc, @argv parameters from main() to this function, it is possible 853 * to pass %NULL if @argv is not available or commandline handling is not 854 * required. Note that on Windows, @argc and @argv are ignored, and 855 * g_win32_get_command_line() is called internally (for proper support 856 * of Unicode commandline arguments). 857 * 858 * #GApplication will attempt to parse the commandline arguments. You 859 * can add commandline flags to the list of recognised options by way of 860 * g_application_add_main_option_entries(). After this, the 861 * #GApplication::handle-local-options signal is emitted, from which the 862 * application can inspect the values of its #GOptionEntrys. 863 * 864 * #GApplication::handle-local-options is a good place to handle options 865 * such as `--version`, where an immediate reply from the local process is 866 * desired (instead of communicating with an already-running instance). 867 * A #GApplication::handle-local-options handler can stop further processing 868 * by returning a non-negative value, which then becomes the exit status of 869 * the process. 870 * 871 * What happens next depends on the flags: if 872 * %G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining 873 * commandline arguments are sent to the primary instance, where a 874 * #GApplication::command-line signal is emitted. Otherwise, the 875 * remaining commandline arguments are assumed to be a list of files. 876 * If there are no files listed, the application is activated via the 877 * #GApplication::activate signal. If there are one or more files, and 878 * %G_APPLICATION_HANDLES_OPEN was specified then the files are opened 879 * via the #GApplication::open signal. 880 * 881 * If you are interested in doing more complicated local handling of the 882 * commandline then you should implement your own #GApplication subclass 883 * and override local_command_line(). In this case, you most likely want 884 * to return %TRUE from your local_command_line() implementation to 885 * suppress the default handling. See 886 * [gapplication-example-cmdline2.c][https://gitlab.gnome.org/GNOME/glib/-/blob/HEAD/gio/tests/gapplication-example-cmdline2.c] 887 * for an example. 888 * 889 * If, after the above is done, the use count of the application is zero 890 * then the exit status is returned immediately. If the use count is 891 * non-zero then the default main context is iterated until the use count 892 * falls to zero, at which point 0 is returned. 893 * 894 * If the %G_APPLICATION_IS_SERVICE flag is set, then the service will 895 * run for as much as 10 seconds with a use count of zero while waiting 896 * for the message that caused the activation to arrive. After that, 897 * if the use count falls to zero the application will exit immediately, 898 * except in the case that g_application_set_inactivity_timeout() is in 899 * use. 900 * 901 * This function sets the prgname (g_set_prgname()), if not already set, 902 * to the basename of argv[0]. 903 * 904 * Much like g_main_loop_run(), this function will acquire the main context 905 * for the duration that the application is running. 906 * 907 * Since 2.40, applications that are not explicitly flagged as services 908 * or launchers (ie: neither %G_APPLICATION_IS_SERVICE or 909 * %G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the 910 * default handler for local_command_line) if "--gapplication-service" 911 * was given in the command line. If this flag is present then normal 912 * commandline processing is interrupted and the 913 * %G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise" 914 * solution whereby running an application directly from the commandline 915 * will invoke it in the normal way (which can be useful for debugging) 916 * while still allowing applications to be D-Bus activated in service 917 * mode. The D-Bus service file should invoke the executable with 918 * "--gapplication-service" as the sole commandline argument. This 919 * approach is suitable for use by most graphical applications but 920 * should not be used from applications like editors that need precise 921 * control over when processes invoked via the commandline will exit and 922 * what their exit status will be. 923 * 924 * Params: 925 * argv = the argv from main(), or %NULL 926 * 927 * Returns: the exit status 928 * 929 * Since: 2.28 930 */ 931 public int run(string[] argv) 932 { 933 return g_application_run(gApplication, cast(int)argv.length, Str.toStringzArray(argv)); 934 } 935 936 /** 937 * Sends a notification on behalf of @application to the desktop shell. 938 * There is no guarantee that the notification is displayed immediately, 939 * or even at all. 940 * 941 * Notifications may persist after the application exits. It will be 942 * D-Bus-activated when the notification or one of its actions is 943 * activated. 944 * 945 * Modifying @notification after this call has no effect. However, the 946 * object can be reused for a later call to this function. 947 * 948 * @id may be any string that uniquely identifies the event for the 949 * application. It does not need to be in any special format. For 950 * example, "new-message" might be appropriate for a notification about 951 * new messages. 952 * 953 * If a previous notification was sent with the same @id, it will be 954 * replaced with @notification and shown again as if it was a new 955 * notification. This works even for notifications sent from a previous 956 * execution of the application, as long as @id is the same string. 957 * 958 * @id may be %NULL, but it is impossible to replace or withdraw 959 * notifications without an id. 960 * 961 * If @notification is no longer relevant, it can be withdrawn with 962 * g_application_withdraw_notification(). 963 * 964 * Params: 965 * id = id of the notification, or %NULL 966 * notification = the #GNotification to send 967 * 968 * Since: 2.40 969 */ 970 public void sendNotification(string id, Notification notification) 971 { 972 g_application_send_notification(gApplication, Str.toStringz(id), (notification is null) ? null : notification.getNotificationStruct()); 973 } 974 975 /** 976 * This used to be how actions were associated with a #GApplication. 977 * Now there is #GActionMap for that. 978 * 979 * Deprecated: Use the #GActionMap interface instead. Never ever 980 * mix use of this API with use of #GActionMap on the same @application 981 * or things will go very badly wrong. This function is known to 982 * introduce buggy behaviour (ie: signals not emitted on changes to the 983 * action group), so you should really use #GActionMap instead. 984 * 985 * Params: 986 * actionGroup = a #GActionGroup, or %NULL 987 * 988 * Since: 2.28 989 */ 990 public void setActionGroup(ActionGroupIF actionGroup) 991 { 992 g_application_set_action_group(gApplication, (actionGroup is null) ? null : actionGroup.getActionGroupStruct()); 993 } 994 995 /** 996 * Sets the unique identifier for @application. 997 * 998 * The application id can only be modified if @application has not yet 999 * been registered. 1000 * 1001 * If non-%NULL, the application id must be valid. See 1002 * g_application_id_is_valid(). 1003 * 1004 * Params: 1005 * applicationId = the identifier for @application 1006 * 1007 * Since: 2.28 1008 */ 1009 public void setApplicationId(string applicationId) 1010 { 1011 g_application_set_application_id(gApplication, Str.toStringz(applicationId)); 1012 } 1013 1014 /** 1015 * Sets or unsets the default application for the process, as returned 1016 * by g_application_get_default(). 1017 * 1018 * This function does not take its own reference on @application. If 1019 * @application is destroyed then the default application will revert 1020 * back to %NULL. 1021 * 1022 * Since: 2.32 1023 */ 1024 public void setDefault() 1025 { 1026 g_application_set_default(gApplication); 1027 } 1028 1029 /** 1030 * Sets the flags for @application. 1031 * 1032 * The flags can only be modified if @application has not yet been 1033 * registered. 1034 * 1035 * See #GApplicationFlags. 1036 * 1037 * Params: 1038 * flags = the flags for @application 1039 * 1040 * Since: 2.28 1041 */ 1042 public void setFlags(GApplicationFlags flags) 1043 { 1044 g_application_set_flags(gApplication, flags); 1045 } 1046 1047 /** 1048 * Sets the current inactivity timeout for the application. 1049 * 1050 * This is the amount of time (in milliseconds) after the last call to 1051 * g_application_release() before the application stops running. 1052 * 1053 * This call has no side effects of its own. The value set here is only 1054 * used for next time g_application_release() drops the use count to 1055 * zero. Any timeouts currently in progress are not impacted. 1056 * 1057 * Params: 1058 * inactivityTimeout = the timeout, in milliseconds 1059 * 1060 * Since: 2.28 1061 */ 1062 public void setInactivityTimeout(uint inactivityTimeout) 1063 { 1064 g_application_set_inactivity_timeout(gApplication, inactivityTimeout); 1065 } 1066 1067 /** 1068 * Adds a description to the @application option context. 1069 * 1070 * See g_option_context_set_description() for more information. 1071 * 1072 * Params: 1073 * description = a string to be shown in `--help` output 1074 * after the list of options, or %NULL 1075 * 1076 * Since: 2.56 1077 */ 1078 public void setOptionContextDescription(string description) 1079 { 1080 g_application_set_option_context_description(gApplication, Str.toStringz(description)); 1081 } 1082 1083 /** 1084 * Sets the parameter string to be used by the commandline handling of @application. 1085 * 1086 * This function registers the argument to be passed to g_option_context_new() 1087 * when the internal #GOptionContext of @application is created. 1088 * 1089 * See g_option_context_new() for more information about @parameter_string. 1090 * 1091 * Params: 1092 * parameterString = a string which is displayed 1093 * in the first line of `--help` output, after the usage summary `programname [OPTION...]`. 1094 * 1095 * Since: 2.56 1096 */ 1097 public void setOptionContextParameterString(string parameterString) 1098 { 1099 g_application_set_option_context_parameter_string(gApplication, Str.toStringz(parameterString)); 1100 } 1101 1102 /** 1103 * Adds a summary to the @application option context. 1104 * 1105 * See g_option_context_set_summary() for more information. 1106 * 1107 * Params: 1108 * summary = a string to be shown in `--help` output 1109 * before the list of options, or %NULL 1110 * 1111 * Since: 2.56 1112 */ 1113 public void setOptionContextSummary(string summary) 1114 { 1115 g_application_set_option_context_summary(gApplication, Str.toStringz(summary)); 1116 } 1117 1118 /** 1119 * Sets (or unsets) the base resource path of @application. 1120 * 1121 * The path is used to automatically load various [application 1122 * resources][gresource] such as menu layouts and action descriptions. 1123 * The various types of resources will be found at fixed names relative 1124 * to the given base path. 1125 * 1126 * By default, the resource base path is determined from the application 1127 * ID by prefixing '/' and replacing each '.' with '/'. This is done at 1128 * the time that the #GApplication object is constructed. Changes to 1129 * the application ID after that point will not have an impact on the 1130 * resource base path. 1131 * 1132 * As an example, if the application has an ID of "org.example.app" then 1133 * the default resource base path will be "/org/example/app". If this 1134 * is a #GtkApplication (and you have not manually changed the path) 1135 * then Gtk will then search for the menus of the application at 1136 * "/org/example/app/gtk/menus.ui". 1137 * 1138 * See #GResource for more information about adding resources to your 1139 * application. 1140 * 1141 * You can disable automatic resource loading functionality by setting 1142 * the path to %NULL. 1143 * 1144 * Changing the resource base path once the application is running is 1145 * not recommended. The point at which the resource path is consulted 1146 * for forming paths for various purposes is unspecified. When writing 1147 * a sub-class of #GApplication you should either set the 1148 * #GApplication:resource-base-path property at construction time, or call 1149 * this function during the instance initialization. Alternatively, you 1150 * can call this function in the #GApplicationClass.startup virtual function, 1151 * before chaining up to the parent implementation. 1152 * 1153 * Params: 1154 * resourcePath = the resource path to use 1155 * 1156 * Since: 2.42 1157 */ 1158 public void setResourceBasePath(string resourcePath) 1159 { 1160 g_application_set_resource_base_path(gApplication, Str.toStringz(resourcePath)); 1161 } 1162 1163 /** 1164 * Destroys a binding between @property and the busy state of 1165 * @application that was previously created with 1166 * g_application_bind_busy_property(). 1167 * 1168 * Params: 1169 * object = a #GObject 1170 * property = the name of a boolean property of @object 1171 * 1172 * Since: 2.44 1173 */ 1174 public void unbindBusyProperty(ObjectG object, string property) 1175 { 1176 g_application_unbind_busy_property(gApplication, (object is null) ? null : object.getObjectGStruct(), Str.toStringz(property)); 1177 } 1178 1179 /** 1180 * Decreases the busy count of @application. 1181 * 1182 * When the busy count reaches zero, the new state will be propagated 1183 * to other processes. 1184 * 1185 * This function must only be called to cancel the effect of a previous 1186 * call to g_application_mark_busy(). 1187 * 1188 * Since: 2.38 1189 */ 1190 public void unmarkBusy() 1191 { 1192 g_application_unmark_busy(gApplication); 1193 } 1194 1195 /** 1196 * Withdraws a notification that was sent with 1197 * g_application_send_notification(). 1198 * 1199 * This call does nothing if a notification with @id doesn't exist or 1200 * the notification was never sent. 1201 * 1202 * This function works even for notifications sent in previous 1203 * executions of this application, as long @id is the same as it was for 1204 * the sent notification. 1205 * 1206 * Note that notifications are dismissed when the user clicks on one 1207 * of the buttons in a notification or triggers its default action, so 1208 * there is no need to explicitly withdraw the notification in that case. 1209 * 1210 * Params: 1211 * id = id of a previously sent notification 1212 * 1213 * Since: 2.40 1214 */ 1215 public void withdrawNotification(string id) 1216 { 1217 g_application_withdraw_notification(gApplication, Str.toStringz(id)); 1218 } 1219 1220 /** 1221 * The ::activate signal is emitted on the primary instance when an 1222 * activation occurs. See g_application_activate(). 1223 */ 1224 gulong addOnActivate(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1225 { 1226 return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1227 } 1228 1229 /** 1230 * The ::command-line signal is emitted on the primary instance when 1231 * a commandline is not handled locally. See g_application_run() and 1232 * the #GApplicationCommandLine documentation for more information. 1233 * 1234 * Params: 1235 * commandLine = a #GApplicationCommandLine representing the 1236 * passed commandline 1237 * 1238 * Returns: An integer that is set as the exit status for the calling 1239 * process. See g_application_command_line_set_exit_status(). 1240 */ 1241 gulong addOnCommandLine(int delegate(ApplicationCommandLine, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1242 { 1243 return Signals.connect(this, "command-line", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1244 } 1245 1246 /** 1247 * The ::handle-local-options signal is emitted on the local instance 1248 * after the parsing of the commandline options has occurred. 1249 * 1250 * You can add options to be recognised during commandline option 1251 * parsing using g_application_add_main_option_entries() and 1252 * g_application_add_option_group(). 1253 * 1254 * Signal handlers can inspect @options (along with values pointed to 1255 * from the @arg_data of an installed #GOptionEntrys) in order to 1256 * decide to perform certain actions, including direct local handling 1257 * (which may be useful for options like --version). 1258 * 1259 * In the event that the application is marked 1260 * %G_APPLICATION_HANDLES_COMMAND_LINE the "normal processing" will 1261 * send the @options dictionary to the primary instance where it can be 1262 * read with g_application_command_line_get_options_dict(). The signal 1263 * handler can modify the dictionary before returning, and the 1264 * modified dictionary will be sent. 1265 * 1266 * In the event that %G_APPLICATION_HANDLES_COMMAND_LINE is not set, 1267 * "normal processing" will treat the remaining uncollected command 1268 * line arguments as filenames or URIs. If there are no arguments, 1269 * the application is activated by g_application_activate(). One or 1270 * more arguments results in a call to g_application_open(). 1271 * 1272 * If you want to handle the local commandline arguments for yourself 1273 * by converting them to calls to g_application_open() or 1274 * g_action_group_activate_action() then you must be sure to register 1275 * the application first. You should probably not call 1276 * g_application_activate() for yourself, however: just return -1 and 1277 * allow the default handler to do it for you. This will ensure that 1278 * the `--gapplication-service` switch works properly (i.e. no activation 1279 * in that case). 1280 * 1281 * Note that this signal is emitted from the default implementation of 1282 * local_command_line(). If you override that function and don't 1283 * chain up then this signal will never be emitted. 1284 * 1285 * You can override local_command_line() if you need more powerful 1286 * capabilities than what is provided here, but this should not 1287 * normally be required. 1288 * 1289 * Params: 1290 * options = the options dictionary 1291 * 1292 * Returns: an exit code. If you have handled your options and want 1293 * to exit the process, return a non-negative option, 0 for success, 1294 * and a positive value for failure. To continue, return -1 to let 1295 * the default option processing continue. 1296 * 1297 * Since: 2.40 1298 */ 1299 gulong addOnHandleLocalOptions(int delegate(VariantDict, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1300 { 1301 return Signals.connect(this, "handle-local-options", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1302 } 1303 1304 /** 1305 * The ::name-lost signal is emitted only on the registered primary instance 1306 * when a new instance has taken over. This can only happen if the application 1307 * is using the %G_APPLICATION_ALLOW_REPLACEMENT flag. 1308 * 1309 * The default handler for this signal calls g_application_quit(). 1310 * 1311 * Returns: %TRUE if the signal has been handled 1312 * 1313 * Since: 2.60 1314 */ 1315 gulong addOnNameLost(bool delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1316 { 1317 return Signals.connect(this, "name-lost", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1318 } 1319 1320 /** 1321 * The ::open signal is emitted on the primary instance when there are 1322 * files to open. See g_application_open() for more information. 1323 * 1324 * Params: 1325 * files = an array of #GFiles 1326 * nFiles = the length of @files 1327 * hint = a hint provided by the calling instance 1328 */ 1329 gulong addOnOpen(void delegate(void*, int, string, Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1330 { 1331 return Signals.connect(this, "open", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1332 } 1333 1334 /** 1335 * The ::shutdown signal is emitted only on the registered primary instance 1336 * immediately after the main loop terminates. 1337 */ 1338 gulong addOnShutdown(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1339 { 1340 return Signals.connect(this, "shutdown", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1341 } 1342 1343 /** 1344 * The ::startup signal is emitted on the primary instance immediately 1345 * after registration. See g_application_register(). 1346 */ 1347 gulong addOnStartup(void delegate(Application) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1348 { 1349 return Signals.connect(this, "startup", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1350 } 1351 }